import abi from "./abi.js"


const contractAddress="0x20711cA49599f9C3945fbAA528Dd52bD25a9E07b";

let web3 = new Web3(window.ethereum)

let contract = new web3.eth.Contract(abi,contractAddress)

async function connectWallet(){
    const accounts = await window.ethereum
      .request({ method: "eth_requestAccounts" })
      .catch((err) => {
        if (err.code === 4001) {
          // EIP-1193 userRejectedRequest error.
          // If this happens, the user rejected the connection request.
          console.log("Please connect to MetaMask.")
        } else {
          console.error(err)
        }
      })

      console.log("account",accounts)
      const account = accounts[0]

      connectInfo.innerHTML = account;

}

async function createTweet(){
  const account = await web3.eth.getAccounts()
  console.log(textareaRef.value)
  await contract.methods.createTweet(textareaRef.value).send({
    from:account[0]
  })
  let allTweets = await contract.methods.getAllTweets(account[0]).call()
  console.log("allTweets",allTweets)

}

  window.connectWallet = connectWallet;
  window.createTweet = createTweet;
// connectWallet()